package com.shenbianyun.bosskgpay.service.invoice;

import com.shenbianyun.bosskgpay.constant.MerInfoConstant;
import com.shenbianyun.bosskgpay.entity.Merchant;
import com.shenbianyun.bosskgpay.entity.RequestMessage;
import com.shenbianyun.bosskgpay.entity.invoice.QueryInvoiceAvailableAmtReqModel;
import com.shenbianyun.bosskgpay.utils.*;

/**
 * @Author yvan
 * @Date 2021/11/23 10:20:55
 * @Description //查询商户可开票金额6012
 * 可固定业务参数
 **/


public class TestQueryInvoiceLimitAmtService {

    public static QueryInvoiceAvailableAmtReqModel  queryInvoiceAvailableAmt= null;

    static Merchant mer = null;

    public static void main(String[] args) throws Exception {
        runTestQueryInvoiceLimitAmtService();
    }

    public static void runTestQueryInvoiceLimitAmtService() throws Exception {

        mer = new Merchant();
        /*
         * 商户id
         * */
        mer.setMerid(MerInfoConstant.MER_ID);
        /*
         * 商户私钥
         * */
        mer.setPriKey(MerInfoConstant.MER_PRIVATE_KEY);
        /*
         * 商户公钥
         * */
        mer.setPubKey(MerInfoConstant.MER_PUBLIC_KEY);
        /*
         * 商户签名
         * */
        mer.setInterKey(MerInfoConstant.INTER_KEY);

        //公共参数
        RequestMessage rm = new RequestMessage();
        //接口地址
        rm.setFunCode("6012");
        rm.setMerId(mer.getMerid());
        rm.setVersion(MerInfoConstant.API_VERSION);
        rm.setReqId(rm.getFunCode() + System.currentTimeMillis());

        //业务参数
        queryInvoiceAvailableAmt = new QueryInvoiceAvailableAmtReqModel(30481L);

        //reqData转json
        String reqData = JsonUtils.toJson(queryInvoiceAvailableAmt);
        System.out.println("reqDatajson= " + reqData);

        //reqData加密
        byte[] bs = DESUtils.encrypt(reqData.getBytes(MerInfoConstant.CHARSET_UTF_8), mer.getInterKey());
        String reqDataEncrypt = Base64Utils.encodeToString(bs);
        rm.setReqData(reqDataEncrypt);
        rm.setSign(RSAUtils.sign(reqDataEncrypt, mer.getPriKey()));

        String reqStr = JsonUtils.toJson(rm);
        System.out.println("请求数据：" + reqStr);

        //发送请求
        String resData = HttpClientHelper.sendPost(MerInfoConstant.OMS_TEST_URL, "application/json", reqStr, "POST", MerInfoConstant.CHARSET_UTF_8);
        System.out.println(resData);

    }
}
